'use strict';
var cmsControllers = angular.module('cmsControllers');

cmsControllers
    .controller('CmsCtrl', ['$rootScope', '$scope', '$routeParams', '$timeout', '$log', '$modal', 'Constant', 'Nav', 'App', 'Subscription',
                    function ($rootScope, $scope, $routeParams, $timeout, $log, $modal, Constant, Nav, App, Subscription) {
        $rootScope.CurrentAppId = $routeParams.appId;

        App.get({appId:  $routeParams.appId}, function(json) {
            $rootScope.CurrentApp = json.data.app;
            $scope.menuItems = json.data.subs;
        });

        $scope.showSub = function () {
            $timeout(function() {

                $scope.menu = true;
                $("#cms-header").show();
                $scope.content = '/ext/components/' + $rootScope.CurrentSub.code
                    + '/cms/view/main.html';
                Nav.preview();
            }, 100);
        },

        $scope.config = function () {
            $timeout(function() {
                $scope.menu = false;
                $scope.content = 'views/app/config.html';
                $("#cms-header").hide();
           }, 1);
        },

		$scope.selectTemplate = function () {
			var modalInstance = $modal.open({
			  templateUrl: 'views/cms/templateSelection.html',
			  controller: 'TemplateCtrl',
              windowClass: 'modal-c',
			  resolve: {

			  }
			});

			modalInstance.result.then(function (selectedItem) {
			    //$scope.selected = selectedItem;
			}, function () {
                //$log.info('Modal dismissed at: ' + new Date());
			});
        }
}]);




